<!DOCTYPE html><html><head><title>Ext.DomQuery | Ext JS 4.0 Documentation</title><script type="text/javascript" src="../ext-all.js"></script><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../scrollbars.css" type="text/css"><link rel="stylesheet" href="../docs.css" type="text/css"><link id="styleCss" rel="stylesheet" href="../style.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script><link rel="stylesheet" href="../prettify.css" type="text/css"><!-- link(rel: 'stylesheet', href: req.baseURL + '/css/ext4.css', type: 'text/css')--><link rel="shortcut icon" type="image/ico" href="../favicon.ico"><!--[if IE]>
<style type="text/css">.head-band { display: none; }
.header { border: 0; top: 0; left: 0px; background: url(../header.gif) repeat-x; }
.doc-tab .members .member a.more { background-color: #efefef; }
</style><link rel="stylesheet" href="/new/css/ie.css" type="text/css"><![endif]-->
</head><body id="ext-body" class="iScroll"><div id="notice" class="notice">For up to date documentation and features, visit 
<a href="http://docs.sencha.com/ext-js/4-0">http://docs.sencha.com/ext-js/4-0</a></div><div class="wrapper"><div class="head-band"></div><div class="header"><h2><a href="../index.html">Sencha Documentation</a></h2></div><div id="search"><form><input type="text" placeholder="Search" id="search-field" autocomplete="off" name="q"></form><div id="search-box"></div></div><div id="treePanel"></div><div id="container"><script type="text/javascript">

    req = {
        liveURL: '.',
        standAloneMode: true,
        origDocClass: 'Ext.DomQuery',
        docClass: 'Ext.DomQuery',
        docReq: 'Ext.DomQuery',
        version: '4.0',
        baseURL: '.',
        baseDocURL: '.',
        baseProdURL: '.'
    };

    clsInfo = {};



</script>

<script type="text/javascript" src="../search.js"></script>
<!--script type="text/javascript" src="/new/javascripts/app/examples.js"></script-->
<script type="text/javascript" src="../class_tree.js"></script>
<script type="text/javascript" src="../class_doc.js"></script>
<script type="text/javascript">
    req.source = 'DomQuery.html#Ext-DomQuery';
    clsInfo = {"methods":["compile","filter","is","jsSelect","selectNode","selectNumber","selectValue"],"cfgs":[],"properties":["matchers","operators","pseudos"],"events":[],"subclasses":[]};
    Ext.onReady(function() {
        Ext.create('Docs.classPanel');
    });
</script><div id="top-block" class="top-block"><h1 id="clsTitle" class="cls"><a href="../source/DomQuery.html#Ext-DomQuery" target="_blank">Ext.DomQuery</a></h1></div><div id="docContent"><div id="doc-overview-content"><div class="lft"><p>Provides high performance selector/xpath processing by compiling queries into reusable functions. New pseudo classes and matchers can be plugged. It works on HTML and XML documents (if a content node is passed in).</p>

<p>
DomQuery supports most of the <a href="http://www.w3.org/TR/2005/WD-css3-selectors-20051215/#selectors">CSS3 selectors spec</a>, along with some custom selectors and basic XPath.</p>




<p>
All selectors, attribute filters and pseudos below can be combined infinitely in any order. For example "div.foo:nth-child(odd)[@foo=bar].bar:first" would be a perfectly valid selector. Node filters are processed in the order in which they appear, which allows you to optimize your queries for your document structure.
</p>


<h4>Element Selectors:</h4>


<ul class="list">
    <li> <b>*</b> any element</li>
    <li> <b>E</b> an element with the tag E</li>
    <li> <b>E F</b> All descendent elements of E that have the tag F</li>
    <li> <b>E > F</b> or <b>E/F</b> all direct children elements of E that have the tag F</li>
    <li> <b>E + F</b> all elements with the tag F that are immediately preceded by an element with the tag E</li>
    <li> <b>E ~ F</b> all elements with the tag F that are preceded by a sibling element with the tag E</li>
</ul>


<h4>Attribute Selectors:</h4>


<p>The use of &#64; and quotes are optional. For example, div[&#64;foo='bar'] is also a valid attribute selector.</p>


<ul class="list">
    <li> <b>E[foo]</b> has an attribute "foo"</li>
    <li> <b>E[foo=bar]</b> has an attribute "foo" that equals "bar"</li>
    <li> <b>E[foo^=bar]</b> has an attribute "foo" that starts with "bar"</li>
    <li> <b>E[foo$=bar]</b> has an attribute "foo" that ends with "bar"</li>
    <li> <b>E[foo*=bar]</b> has an attribute "foo" that contains the substring "bar"</li>
    <li> <b>E[foo%=2]</b> has an attribute "foo" that is evenly divisible by 2</li>
    <li> <b>E[foo!=bar]</b> attribute "foo" does not equal "bar"</li>
</ul>


<h4>Pseudo Classes:</h4>


<ul class="list">
    <li> <b>E:first-child</b> E is the first child of its parent</li>
    <li> <b>E:last-child</b> E is the last child of its parent</li>
    <li> <b>E:nth-child(<i>n</i>)</b> E is the <i>n</i>th child of its parent (1 based as per the spec)</li>
    <li> <b>E:nth-child(odd)</b> E is an odd child of its parent</li>
    <li> <b>E:nth-child(even)</b> E is an even child of its parent</li>
    <li> <b>E:only-child</b> E is the only child of its parent</li>
    <li> <b>E:checked</b> E is an element that is has a checked attribute that is true (e.g. a radio or checkbox) </li>
    <li> <b>E:first</b> the first E in the resultset</li>
    <li> <b>E:last</b> the last E in the resultset</li>
    <li> <b>E:nth(<i>n</i>)</b> the <i>n</i>th E in the resultset (1 based)</li>
    <li> <b>E:odd</b> shortcut for :nth-child(odd)</li>
    <li> <b>E:even</b> shortcut for :nth-child(even)</li>
    <li> <b>E:contains(foo)</b> E's innerHTML contains the substring "foo"</li>
    <li> <b>E:nodeValue(foo)</b> E contains a textNode with a nodeValue that equals "foo"</li>
    <li> <b>E:not(S)</b> an E element that does not match simple selector S</li>
    <li> <b>E:has(S)</b> an E element that has a descendent that matches simple selector S</li>
    <li> <b>E:next(S)</b> an E element whose next sibling matches simple selector S</li>
    <li> <b>E:prev(S)</b> an E element whose previous sibling matches simple selector S</li>
    <li> <b>E:any(S1|S2|S2)</b> an E element which matches any of the simple selectors S1, S2 or S3//\\</li>
</ul>


<h4>CSS Value Selectors:</h4>


<ul class="list">
    <li> <b>E{display=none}</b> css value "display" that equals "none"</li>
    <li> <b>E{display^=none}</b> css value "display" that starts with "none"</li>
    <li> <b>E{display$=none}</b> css value "display" that ends with "none"</li>
    <li> <b>E{display*=none}</b> css value "display" that contains the substring "none"</li>
    <li> <b>E{display%=2}</b> css value "display" that is evenly divisible by 2</li>
    <li> <b>E{display!=none}</b> css value "display" that does not equal "none"</li>
</ul>

<div class="members"><div class="m-properties"><a name="properties"></a><div class="definedBy">Defined By</div><h3 class="prp p">Properties</h3><div id="property-matchers" class="member f ni"><a href="Ext.DomQuery.html#property-matchers" rel="property-matchers" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.DomQuery.html" class="definedIn docClass">Ext.DomQuery</a><br/><a href="../source/DomQuery.html#Ext-DomQuery-property-matchers" class="viewSource">view source</a></div><a name="matchers"></a><a name="property-matchers"></a><a href="Ext.DomQuery.html#" rel="property-matchers" class="cls expand">matchers</a><span> : Object</span></div><div class="description"><div class="short">Collection of matching regular expressions and code snippets.
Each capture group within () will be replace the {} in ...</div><div class="long"><p>Collection of matching regular expressions and code snippets.
Each capture group within () will be replace the {} in the select
statement as specified by their index.</p>
</div></div></div><div id="property-operators" class="member ni"><a href="Ext.DomQuery.html#property-operators" rel="property-operators" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.DomQuery.html" class="definedIn docClass">Ext.DomQuery</a><br/><a href="../source/DomQuery.html#Ext-DomQuery-property-operators" class="viewSource">view source</a></div><a name="operators"></a><a name="property-operators"></a><a href="Ext.DomQuery.html#" rel="property-operators" class="cls expand">operators</a><span> : Object</span></div><div class="description"><div class="short">Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
New operator...</div><div class="long"><p>Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
New operators can be added as long as the match the format <i>c</i>= where <i>c</i> is any character other than space, &gt; &lt;.</p>
</div></div></div><div id="property-pseudos" class="member ni"><a href="Ext.DomQuery.html#property-pseudos" rel="property-pseudos" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.DomQuery.html" class="definedIn docClass">Ext.DomQuery</a><br/><a href="../source/DomQuery.html#Ext-DomQuery-property-pseudos" class="viewSource">view source</a></div><a name="pseudos"></a><a name="property-pseudos"></a><a href="Ext.DomQuery.html#" rel="property-pseudos" class="cls expand">pseudos</a><span> : Object</span></div><div class="description"><div class="short">Object hash of "pseudo class" filter functions which are used when filtering selections.
Each function is passed two ...</div><div class="long"><p>Object hash of "pseudo class" filter functions which are used when filtering selections.
Each function is passed two parameters:</p>

<ul>
<li><p><strong>c</strong> : Array
  An Array of DOM elements to filter.</p></li>
<li><p><strong>v</strong> : String
  The argument (if any) supplied in the selector.</p></li>
</ul>


<p>A filter function returns an Array of DOM elements which conform to the pseudo class.
In addition to the provided pseudo classes listed above such as <code>first-child</code> and <code>nth-child</code>,
developers may add additional, custom psuedo class filters to select elements according to application-specific requirements.</p>

<p>For example, to filter <code>a</code> elements to only return links to <strong>external</strong> resources:</p>

<pre><code>Ext.DomQuery.pseudos.external = function(c, v){
    var r = [], ri = -1;
    for(var i = 0, ci; ci = c[i]; i++){
        // Include in result set only if it's a link to an external resource
        if(ci.hostname != location.hostname){
            r[++ri] = ci;
        }
    }
    return r;
};
</code></pre>

<p>Then external links could be gathered with the following statement:</p>

<pre><code>var externalLinks = Ext.select("a:external");
</code></pre>
</div></div></div></div><div class="m-methods"><a name="methods"></a><div class="definedBy">Defined By</div><h3 class="mth p">Methods</h3><div id="method-compile" class="member f ni"><a href="Ext.DomQuery.html#method-compile" rel="method-compile" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.DomQuery.html" class="definedIn docClass">Ext.DomQuery</a><br/><a href="../source/DomQuery.html#Ext-DomQuery-method-compile" class="viewSource">view source</a></div><a name="compile"></a><a name="method-compile"></a><a href="Ext.DomQuery.html#" rel="method-compile" class="cls expand">compile</a>(
<span class="pre">String selector, [String type]</span>)
 : Function</div><div class="description"><div class="short">Compiles a selector/xpath query into a reusable function. The returned function
takes one parameter "root" (optional)...</div><div class="long"><p>Compiles a selector/xpath query into a reusable function. The returned function
takes one parameter "root" (optional), which is the context node from where the query should start.</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">selector</span> : String<div class="sub-desc"><p>The selector/xpath query</p>
</div></li><li><span class="pre">type</span> : String<div class="sub-desc"><p>(optional) Either "select" (the default) or "simple" for a simple selector match</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Function</span>&nbsp; &nbsp;
</li></ul></div></div></div><div id="method-filter" class="member ni"><a href="Ext.DomQuery.html#method-filter" rel="method-filter" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.DomQuery.html" class="definedIn docClass">Ext.DomQuery</a><br/><a href="../source/DomQuery.html#Ext-DomQuery-method-filter" class="viewSource">view source</a></div><a name="filter"></a><a name="method-filter"></a><a href="Ext.DomQuery.html#" rel="method-filter" class="cls expand">filter</a>(
<span class="pre">Array el, String selector, Boolean nonMatches</span>)
 : Array</div><div class="description"><div class="short"><p>Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)</p>
</div><div class="long"><p>Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">el</span> : Array<div class="sub-desc"><p>An array of elements to filter</p>
</div></li><li><span class="pre">selector</span> : String<div class="sub-desc"><p>The simple selector to test</p>
</div></li><li><span class="pre">nonMatches</span> : Boolean<div class="sub-desc"><p>If true, it returns the elements that DON'T match
the selector instead of the ones that match</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Array</span>&nbsp; &nbsp;<p>An Array of DOM elements which match the selector. If there are
no matches, and empty Array is returned.</p>
</li></ul></div></div></div><div id="method-is" class="member ni"><a href="Ext.DomQuery.html#method-is" rel="method-is" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.DomQuery.html" class="definedIn docClass">Ext.DomQuery</a><br/><a href="../source/DomQuery.html#Ext-DomQuery-method-is" class="viewSource">view source</a></div><a name="is"></a><a name="method-is"></a><a href="Ext.DomQuery.html#" rel="method-is" class="cls expand">is</a>(
<span class="pre">String/HTMLElement/Array el, String selector</span>)
 : Boolean</div><div class="description"><div class="short"><p>Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)</p>
</div><div class="long"><p>Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">el</span> : String/HTMLElement/Array<div class="sub-desc"><p>An element id, element or array of elements</p>
</div></li><li><span class="pre">selector</span> : String<div class="sub-desc"><p>The simple selector to test</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Boolean</span>&nbsp; &nbsp;
</li></ul></div></div></div><div id="method-jsSelect" class="member ni"><a href="Ext.DomQuery.html#method-jsSelect" rel="method-jsSelect" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.DomQuery.html" class="definedIn docClass">Ext.DomQuery</a><br/><a href="../source/DomQuery.html#Ext-DomQuery-method-jsSelect" class="viewSource">view source</a></div><a name="jsSelect"></a><a name="method-jsSelect"></a><a href="Ext.DomQuery.html#" rel="method-jsSelect" class="cls expand">jsSelect</a>(
<span class="pre">String selector, [Node/String root], Object type</span>)
 : Array</div><div class="description"><div class="short"><p>Selects a group of elements.</p>
</div><div class="long"><p>Selects a group of elements.</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">selector</span> : String<div class="sub-desc"><p>The selector/xpath query (can be a comma separated list of selectors)</p>
</div></li><li><span class="pre">root</span> : Node/String<div class="sub-desc"><p>(optional) The start of the query (defaults to document).</p>
</div></li><li><span class="pre">type</span> : Object<div class="sub-desc">
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Array</span>&nbsp; &nbsp;<p>An Array of DOM elements which match the selector. If there are
no matches, and empty Array is returned.</p>
</li></ul></div></div></div><div id="method-selectNode" class="member ni"><a href="Ext.DomQuery.html#method-selectNode" rel="method-selectNode" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.DomQuery.html" class="definedIn docClass">Ext.DomQuery</a><br/><a href="../source/DomQuery.html#Ext-DomQuery-method-selectNode" class="viewSource">view source</a></div><a name="selectNode"></a><a name="method-selectNode"></a><a href="Ext.DomQuery.html#" rel="method-selectNode" class="cls expand">selectNode</a>(
<span class="pre">String selector, [Node root]</span>)
 : Element</div><div class="description"><div class="short"><p>Selects a single element.</p>
</div><div class="long"><p>Selects a single element.</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">selector</span> : String<div class="sub-desc"><p>The selector/xpath query</p>
</div></li><li><span class="pre">root</span> : Node<div class="sub-desc"><p>(optional) The start of the query (defaults to document).</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Element</span>&nbsp; &nbsp;<p>The DOM element which matched the selector.</p>
</li></ul></div></div></div><div id="method-selectNumber" class="member ni"><a href="Ext.DomQuery.html#method-selectNumber" rel="method-selectNumber" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.DomQuery.html" class="definedIn docClass">Ext.DomQuery</a><br/><a href="../source/DomQuery.html#Ext-DomQuery-method-selectNumber" class="viewSource">view source</a></div><a name="selectNumber"></a><a name="method-selectNumber"></a><a href="Ext.DomQuery.html#" rel="method-selectNumber" class="cls expand">selectNumber</a>(
<span class="pre">String selector, [Node root], Number defaultValue</span>)
 : Number</div><div class="description"><div class="short"><p>Selects the value of a node, parsing integers and floats. Returns the defaultValue, or 0 if none is specified.</p>
</div><div class="long"><p>Selects the value of a node, parsing integers and floats. Returns the defaultValue, or 0 if none is specified.</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">selector</span> : String<div class="sub-desc"><p>The selector/xpath query</p>
</div></li><li><span class="pre">root</span> : Node<div class="sub-desc"><p>(optional) The start of the query (defaults to document).</p>
</div></li><li><span class="pre">defaultValue</span> : Number<div class="sub-desc">
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Number</span>&nbsp; &nbsp;
</li></ul></div></div></div><div id="method-selectValue" class="member ni"><a href="Ext.DomQuery.html#method-selectValue" rel="method-selectValue" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.DomQuery.html" class="definedIn docClass">Ext.DomQuery</a><br/><a href="../source/DomQuery.html#Ext-DomQuery-method-selectValue" class="viewSource">view source</a></div><a name="selectValue"></a><a name="method-selectValue"></a><a href="Ext.DomQuery.html#" rel="method-selectValue" class="cls expand">selectValue</a>(
<span class="pre">String selector, [Node root], String defaultValue</span>)
 : String</div><div class="description"><div class="short"><p>Selects the value of a node, optionally replacing null with the defaultValue.</p>
</div><div class="long"><p>Selects the value of a node, optionally replacing null with the defaultValue.</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">selector</span> : String<div class="sub-desc"><p>The selector/xpath query</p>
</div></li><li><span class="pre">root</span> : Node<div class="sub-desc"><p>(optional) The start of the query (defaults to document).</p>
</div></li><li><span class="pre">defaultValue</span> : String<div class="sub-desc">
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">String</span>&nbsp; &nbsp;
</li></ul></div></div></div></div></div></div></div><div id="pageContent"></div></div></div></div></body></html>